//
//  NetworkHelper.m
//  LoveSport
//
//  Created by Liang Zhang on 14/11/28.
//  Copyright (c) 2014年 bangtianxia. All rights reserved.
//

#import "NetworkHelper.h"

@implementation NetworkHelper

+ (ApiEnum)apiEnumWithFunction:(NSString *)function {
    ApiEnum api = ApiEnumNone;
    //用function(NSString)参数if判断以确定ApiName枚举
    if ([function caseInsensitiveCompare:apiNameUsers] == NSOrderedSame) {
        api = ApiEnumGet_Users;
    }
    return api;
}

+ (BOOL)isNetWorkReachable{
    
    AFNetworkReachabilityManager *afNetworkReachabilityManager = [AFNetworkReachabilityManager sharedManager];
    return afNetworkReachabilityManager.isReachable;
 
}

+ (NSString *)makeMessageOfApiException:(NSInteger)code API:(NSString *)api{
    switch (code) {
        case 0:
            return NSLocalizedString(@"Sever exception", @"Sever exception");
            break;
            
        default:
            return NSLocalizedString(@"API Error!", @"API Error!");
            break;
    }
}

+ (void)startMonitorNetworkConnection{
    AFNetworkReachabilityManager *afNetworkReachabilityManager = [AFNetworkReachabilityManager sharedManager];
    [afNetworkReachabilityManager startMonitoring];
    
    [afNetworkReachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        
        switch (status) {
            case AFNetworkReachabilityStatusNotReachable:{
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWiFi:{
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWWAN:{
                break;
            }
            default:
                break;
        }
    }];
}

+(void)stopMonitorNetworkConnection{
    AFNetworkReachabilityManager *afNetworkReachabilityManager = [AFNetworkReachabilityManager sharedManager];
    [afNetworkReachabilityManager stopMonitoring];
}
@end
